package com.memo4android.model;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
 
public class MaBaseSQLite extends SQLiteOpenHelper {
  
	private static final String CREATE_BDD_tDossier = "CREATE TABLE IF NOT EXISTS tDossier(idDossier INTEGER PRIMARY KEY,titre TEXT NOT NULL);";
    private static final String CREATE_BDD_tNote = "CREATE TABLE IF NOT EXISTS tNote (idNote INTEGER PRIMARY KEY, titre TEXT NOT NULL,texte TEXT NOT NULL,dateCreation INTEGER);";
    private static final String CREATE_BDD_tLienDossierNote = "CREATE TABLE IF NOT EXISTS tLienDossierNote(idDossier INTEGER,idNote INTEGER);";
    private static final String CREATE_BDD_tToDo = "CREATE TABLE IF NOT EXISTS tToDo (idToDo INTEGER PRIMARY KEY, titre TEXT NOT NULL,etat INTEGER);"; //etat 0 ou 1
    private static final String CREATE_BDD_tToDoList = "CREATE TABLE IF NOT EXISTS tToDoList (idToDoList INTEGER PRIMARY KEY, titre TEXT NOT NULL, dateCreation INTEGER, dateEcheance INTEGER, priorite INTEGER);"; //priorite 0 1 ou 2
    private static final String CREATE_BDD_tToDoToDoList = "CREATE TABLE IF NOT EXISTS tLienToDoToDoList (idToDo INTEGER,idToDoList INTEGER);";
    
    private static final String BDD_INSERT_HOME = "INSERT OR REPLACE INTO tDossier (idDossier, titre) VALUES (0, '__HOME');";

    public MaBaseSQLite(Context context, String name, CursorFactory factory, int version) {
		super(context, name, factory, version);
	}
 
	@Override
	public void onCreate(SQLiteDatabase db) {
		//on créé la table à partir de la requte écrite dans la variable CREATE_BDD
		db.execSQL(CREATE_BDD_tDossier);
		db.execSQL(CREATE_BDD_tNote);
		db.execSQL(CREATE_BDD_tLienDossierNote);
		db.execSQL(CREATE_BDD_tToDo);
		db.execSQL(CREATE_BDD_tToDoList);
		db.execSQL(CREATE_BDD_tToDoToDoList);
		db.execSQL(BDD_INSERT_HOME);
	}
 
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		//On peut fait ce qu'on veut ici moi j'ai dŽcidŽ de supprimer la table et de la recrŽer
		//comme a lorsque je change la version les id repartent de 0
		//db.execSQL("DROP TABLE " + TABLE_LIVRES + ";");
		//onCreate(db);
	}
 
}
